-
-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
实现了对用户空间传入指针抽象的UserBufferReader/Writer,来检验用户空间指针地址并提供一定的功能抽象 #326
实现了对用户空间传入指针抽象的UserBufferReader/Writer,来检验用户空间指针地址并提供一定的功能抽象 #326
Conversation
kernel/src/libs/userbuffer.rs
Outdated
/// @return 构造成功返回UserbufferReader实例,否则返回错误码 | ||
/// | ||
pub fn new(addr: *const T, len: usize) -> Result<Self, SystemError> { | ||
if unsafe { !verify_area(addr as u64, (len * core::mem::size_of::<T>()) as u64) } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个verify area不要使用C的,rust版本之前有写过,参考syscall/syscall.rs
kernel/src/libs/userbuffer.rs
Outdated
|
||
#[derive(Debug)] | ||
pub struct UserBufferReader<T> { | ||
addr: *const T, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里可以直接存储数组的引用,这样能够更安全。
现在这样,直接存裸指针的话,后面每次读取,都手动转数组引用。实际上是在一定程度上绕过了借用检查
然后我感觉从通用性考虑,这里完全可以转为&[u8]
在读取函数那里,可以允许通过任意的类型来解析它。这样会更好。
…into userbuffer-dev
No description provided.